import requests,json,time


def profile(uid,session):
    url="https://39.107.209.71/v1/account/profile/get?fr="+uid
    data="t_uid="+uid
    headers={"Accept": "*/*","Accept-Encoding": "gzip, deflate, br","Accept-Language": "zh-Hans-CN;q=1, zh-Hant-CN;q=0.9","Connection": "keep-alive","Content-Length": "13","Content-Type": "application/x-www-form-urlencoded","Cookie": "SESSIONID="+session,"Host": "api-say.immomo.com","User-Agent": "Pott/1.5.0 iOS/136 (iPhone X; iOS 14.0; zh_CN; 2ba242aad8f5436c85772f8ba69b77c1; S1)",}
    res=requests.post(url,data=data,headers=headers,verify=False)
    jsondata=json.loads(res.text)
    if(jsondata['em']=="success"):
        if(jsondata['data']):
            jsondata=jsondata['data']
            nickName=jsondata['nickName']
            reg_city=jsondata['reg_city']
            reg_time=jsondata['reg_time']
            fans=jsondata['fans']
            follow=jsondata['follow']
            gone_city=jsondata['gone_city']
            photo_num=jsondata['photo_num']
            relation=jsondata['relation']
            be_like_mark_num=jsondata['be_like_mark_num']
            placesCount=jsondata['placesCount']
            userdata={}
            userdata['nickName']=nickName
            userdata['reg_city']=reg_city
            userdata['reg_time']=reg_time
            userdata['fans']=fans
            userdata['follow']=follow
            userdata['gone_city']=gone_city
            userdata['photo_num']=photo_num
            userdata['relation']=relation
            userdata['be_like_mark_num']=be_like_mark_num
            userdata['placesCount']=placesCount
            return userdata
        else:
            return 0
    else:
        return 0

def getimage(avatar):
    v1=avatar[0:2]
    v2=avatar[2:4]
    url="https://pin.momocdn.com/pinimage/"
    url+=v1+"/"+v2+"/"+avatar+"_S.jpg"
    return url

def goneCityV2(uid,session):
    url="https://39.107.209.71/v1/account/profile/goneCityV2?fr="+uid
    data="t_uid="+uid
    headers={"Accept": "*/*","Accept-Encoding": "gzip, deflate, br","Accept-Language": "zh-Hans-CN;q=1, zh-Hant-CN;q=0.9","Connection": "keep-alive","Content-Length": "13","Content-Type": "application/x-www-form-urlencoded","Cookie": "SESSIONID="+session,"Host": "api-say.immomo.com","User-Agent": "Pott/1.5.0 iOS/136 (iPhone X; iOS 14.0; zh_CN; 2ba242aad8f5436c85772f8ba69b77c1; S1)",}
    res=requests.post(url,data=data,headers=headers,verify=False)
    jsondata=json.loads(res.text)
    if(jsondata['em']=="success"):
        jsondata=jsondata['data']
        country_num=jsondata['country_num']
        city_num=jsondata['city_num']
        address_num=jsondata['address_num']
        photo_num=jsondata['photo_num']
        area=jsondata['area']
        newMarkNum=jsondata['newMarkNum']
        countrydata=jsondata['country']
        country=""
        city=""
        for i in countrydata:
            country+=i+","
        citydata=jsondata['city']
        for i in citydata:
            city+=i+","
        goneCitydata={}
        goneCitydata['country_num']=country_num
        goneCitydata['city_num']=city_num
        goneCitydata['address_num']=address_num
        goneCitydata['photo_num']=photo_num
        goneCitydata['country']=country
        goneCitydata['city']=city
        goneCitydata['area']=area
        goneCitydata['newMarkNum']=newMarkNum
        return goneCitydata

def userImages(uid,start,session):
    url="https://39.107.209.71/v1/feed/list/userImages?fr="+uid
    url="https://39.107.209.71/v1/feed/list/userImagesOrderByShootTime?fr="+uid
    data="start="+str(start)+"&t_uid="+uid+"&   =feed"
    headers={"Accept": "*/*","Accept-Encoding": "gzip, deflate, br","Accept-Language": "zh-Hans-CN;q=1, zh-Hant-CN;q=0.9","Connection": "keep-alive","Content-Length": "13","Content-Type": "application/x-www-form-urlencoded","Cookie": "SESSIONID="+session,"Host": "api-say.immomo.com","User-Agent": "Pott/1.5.0 iOS/136 (iPhone X; iOS 14.0; zh_CN; 2ba242aad8f5436c85772f8ba69b77c1; S1)",}
    res=requests.post(url,data=data,headers=headers,verify=False)
    jsondata=json.loads(res.text)
    if(jsondata['em']=="success"):
        returndata=[]
        #{"code":"0000","count":0,"data":[]}
        for images in jsondata['data']['list']:
            temp={}
            guid=images['guid']
            desc=images['desc']
            uptime=images['time']
            shooting_time=images['shooting_time']
            x = time.localtime(int(shooting_time))
            pstime = time.strftime("%Y-%m-%d %H:%M:%S",x)
            country=images['country']
            province=images['province']
            city=images['city']
            area=images['area']
            business=images['business']
            address=images['address']
            lat=images['lat']
            lng=images['lng']
            distance=images['distance']
            formattedAddress=images['formattedAddress']
            imageurl=getimage(guid)

            temp['desc']=desc
            temp['uptime']=uptime
            temp['pstime']=pstime
            temp['country']=country
            temp['province']=province
            temp['city']=city
            temp['area']=area
            temp['business']=business
            temp['address']=address
            temp['lat']=lat
            temp['lng']=lng
            temp['distance']=distance
            temp['formattedAddress']=formattedAddress
            temp['imageurl']=imageurl
            returndata.append(temp)
        nextStart=jsondata['data']['nextStart']
        if(nextStart==0):
            return returndata
        else:
            returndata+=userImages(uid,nextStart,session)
            #print("拍摄时间:%s 国家:%s 省份:%s 城市:%s 区域:%s 地址:%s 经度:%s 纬度:%s 格式化地址:%s \n图片链接:%s" %(pstime,country,province,city,area,address,lat,lng,formattedAddress,imageurl))
    return returndata

